﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<VietPay.KooBoo.Business.Models.BatchListViewModel>" %>

<!DOCTYPE html>

<html>
<head runat="server">
<script language="javascript" src="../../../../Scripts/jquery-ui-1.8.12.custom.min.js" type="text/javascript"></script>
    <title>BatchVMSCreateGood</title>
</head>
<body>  
   <h1> Phân phối hàng hóa</h1>
   <h1> Thông tin đơn vị nhận</h1>
    <% using (Html.BeginForm("BatchVMSCreateGood", "Batch", FormMethod.Post, new
       {
           id = "frmProductAdd"
       }))
       {%>
    <%= Html.ValidationSummary(true)%>
    <table width="100%">
        <tbody>
            <% if (Model.DistributorListView != null & Model.DistributorListView.DistributorList.Count() > 0)
               { %>
            <tr>
                <td class="key">
                    Đơn vị nhận (<font color="red">*</font>)
                </td>
                <td>
                    <%=Html.DropDownList("Distributor", new SelectList(Model.DistributorListView.DistributorList, "DistributorID", "DistributorName"), "-- Danh mục Distributor --",new {onchange = "this.form.submit()"})%>
                </td>
            </tr>
            <%} %>
            <tr>
                <td class="key">
                    Số CMTND (<font color="red">*</font>)
                </td>
                <td align="left">
                    <%= Html.TextBoxFor(model => model.ThisPageItemCount, new { style = "width: 256px;", maxlength = 256 })%>
                </td>
            </tr>
            <tr>
                <td class="key">
                    Địa chỉ
                </td>
                <td align="left">
                    <%= Html.TextBoxFor(model => model.ThisPageItemCount, new { style = "width: 256px;", maxlength = 256 })%>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" id="btnSave" value="Lưu" />
                </td>
            </tr>
        </tbody>
    </table>
    <%}
    %>

    <h1> Thông tin lô hàng</h1>
    <% using (Html.BeginForm("BatchVMSCreateGood", "Batch", FormMethod.Post, new
       {
           id = "frmProductAdd"
       }))
       {%>
    <%= Html.ValidationSummary(true)%>
    <table width="100%">
        <tbody>

            <tr>
                <td class="key">
                    Ngày nhập (<font color="red">*</font>)
                </td>
                <td align="left">
                    <%= Html.TextBoxFor(model=>model.ThisPageItemCount, new { style = "width: 256px;", maxlength = 256 })%>
                </td>
            </tr>
            <tr>
                <td class="key">
                    Mã lô
                </td>
                <td align="left">
                    <%= Html.TextBoxFor(model => model.ThisPageItemCount, new { style = "width: 256px;", maxlength = 256 })%>
                </td>
            </tr>
            <tr>
                <td class="key">
                    Loại sản phẩm
                </td>
                <td align="left">
                    <%= Html.TextBoxFor(model => model.ThisPageItemCount, new { style = "width: 256px;", maxlength = 256 })%>
                </td>
            </tr>
            <tr>
                <td class="key">
                    Trạng thái
                </td>
                <td align="left">
                    <%= Html.TextBoxFor(model => model.ThisPageItemCount, new { style = "width: 256px;", maxlength = 256 })%>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" id="Submit1" value="Tìm kiếm" />
                </td>
            </tr>
        </tbody>
    </table>
    <%}
    %>

    <h1> Lô hàng</h1>
    <table id="tbl1">
        <tr>
            <th></th>
            <th>
                BatchID
            </th>
            <th>
                BatchCode
            </th>
            <th>
                CreatedDate
            </th>
            <th>
                UserCreate
            </th>
            <th>
                Description
            </th>
            <th>
                CategoryID
            </th>
            <th>
                CategoryName
            </th>
            
        </tr>
    <% if (Model.BatchList != null)
               {  %>
    <% foreach (var item in Model.BatchList ) { %>
        <tr>
            <td>
                <%: Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) %> |
                <%: Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) %> |
                <%: Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) %>
            </td>
            <td>
                <%: item.BatchID %>
            </td>
            <td>
                <%: item.BatchCode %>
            </td>
            <td>
                <%: String.Format("{0:g}", item.CreatedDate) %>
            </td>
            <td>
                <%: item.UserCreate %>
            </td>
            <td>
                <%: item.DistributorID %>
            </td>
            <td>
                <%: item.ParentDistributorID %>
            </td>
            <td>
                <%: item.Description %>
            </td>
            <td>
                <%: item.CategoryID %>
            </td>
            <td>
                <%: item.CategoryName %>
            </td>
            <td>
                <%: item.Status %>
            </td>
            <td align="center"><input name="input" type="button" value="Xóa" onClick="deleterow(this);"/></td>
        </tr>  

        
    <% }} %>
    <tr>
                <td colspan="2" align="center">
                    <input type="submit" id="Submit2" value="Thêm" onclick="addRow()" />
                    <td>&nbsp;</td>
					<td>&nbsp;</td>
					<td><input name="" type="submit" value="Lưu" class="btn" onclick="submitSharing();"/></td>
                </td>
                
                    
        </tr>
    </table>

    <script type="text/javascript">
    function addRow()
    {
        var tb=document.createElement('tbody');
        var tr=document.createElement('tr');
        var td=new Array();
        var txt=new Array();
        for(var i=0;i<4;i++)
        {
        txt[i]=document.createElement('input');
        txt[i].onblur=function(){saveInput(this);}
        td[i]=document.createElement('td');
        td[i].appendChild(txt[i]);
        tr.appendChild(td[i]);
        }
        tb.appendChild(tr);
        document.getElementById('tbl1').childNodes[document.getElementById('tbl1').childNodes.length-1].appendChild(tb);
    }

    function addRowToTable() {
        var count = $('#tbl1 tr').length;
        var my_row = '<tr>' +
				'<td align="center"> ' +
				'	<input type="text" name="SubjectCode" id="txt_usn_' + count + '" value=""/>' +
				'   <input type="hidden" class="subject-code-value" value=""/>' +
				'</td>' +
				'<td align="center">' +
				'	<input type="text" class="car-company" checked />' +
				'	<input type="hidden" class="car-company-value" value="1" />' +
				'   <input type="hidden" class="subject-type-value" value="USER" />' +
				'</td>' +
				'<td align="center">' +
				'	<input type="text" class="car-model" checked/>' +
				'	<input type="hidden" class="car-model-value" value="1"/>' +
				'</td>' +
				'<td align="center">' +
				'	<input type="text" class="car-transmission" />' +
				'	<input type="hidden" class="car-transmission-value" value="0"/>' +
				'</td>' +
				'<td align="center">' +
				'	<input type="text" class="car-color" />' +
				'	<input type="hidden" class="car-color-value" value="0"/>' +
				'</td>' +
				'<td align="center">' +
				'	<input type="text" class="car-ptdisplacement"  />' +
				'	<input type="hidden" class="car-ptdisplacement-value" value="0"/>' +
				'</td>' +
				'<td align="center">' +
				'	<input type="text" class="car-ocn" />' +
				'	<input type="hidden" class="car-ocn-value" value="0"/>' +
				'</td>' +
				'<td align="center">' +
				'	<input name="input" type="button" value="Xóa" onClick="deleterow(this);"/>' +
				'</td>' +
			'</tr>';
        $('#tbl1').append(my_row);
        //auto complete
        mapAutoComplete('txt_usn_' + count);
        //bindCheckBoxAndHidden();
    }

    function deleterow(source) {
        var row = $(source).parent().parent();
        row.remove();
    }

    function mapAutoComplete(id) {
        //alert("map for:"+id);
        var id = "#" + id;
        $(id).autocomplete({
            source: function (request, response) {
                //alert('Hehe');
                $.post('/Batch/JSONProduct',
					{ q: function () {
					    return $(id).val()
					}
					},
					function (data) {
					    alert('Got data:' + data);
					    response($.map(data, function (item) {
					        return {
					            label: item.UserCode + "-" + item.NameFull + "-" + item.CompanyName,
					            value: item.UserCode,
					            company: item.CompanyName,
					            fullname: item.NameFull,
					            username: item.UserCode
					        }
					    })
                     )
					},
					"json");
        	},
            select: function (event, ui) {
                var row = $(id).parent().parent();
                row.find('.subject-code-value').val(ui.item.username);
                //row.find('.company').html(ui.item.company);
                //row.find('.user-name').val(ui.item.username);
            }
        });
    }

    </script>

</body>
</html>

